import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:icooker/model/reommend_data.dart';
import 'package:cached_network_image/cached_network_image.dart';

/// 轮播图
class HomeBanner extends StatelessWidget {
  final List<Zhuanti> list;

  const HomeBanner(this.list, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      // margin: EdgeInsets.symmetric(horizontal: 8),
      height: 180,
      child: Swiper(
        autoplay: true,
        loop: true,
        duration: 300,
        onTap: (index) {},
        pagination: new SwiperPagination(alignment: Alignment.bottomCenter),
        layout: SwiperLayout.DEFAULT,
        // control: SwiperControl(),
        itemBuilder: (context, index) {
          return AspectRatio(
            aspectRatio: 1 / 1,
            child: CachedNetworkImage(
              fit: BoxFit.fill,
              imageUrl: list[index].img!,
              // 圆角效果实现
              imageBuilder: (context, imageprovider) => Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8),
                    image: DecorationImage(
                        image: imageprovider, fit: BoxFit.fill)),
              ),
              placeholder: (
                BuildContext context,
                String url,
              ) =>
                  Container(
                color: Color(0xFFD6D6D6),
                child: Center(
                  child: SizedBox(
                    width: 30,
                    height: 30,
                    child: CircularProgressIndicator(
                      color: Colors.blueGrey,
                    ),
                  ),
                ),
              ),
            ),
          );
        },
        itemCount: list.length,
      ),
    );
  }
}
